﻿@using YanForum.Engine.ViewModels
@model PostIndex

@{
    ViewBag.Title = "Quản ý bài viết";
    Layout = "~/Areas/Admin/Views/Shared/_Layout.cshtml";
}


@Html.Partial("_partialPostSearch",Model.Options)

<div class="row">
    <div class="col-md-12"> 
        @if(Model.ListPost != null && Model.ListPost.Count > 0){

            <table class="table table-bordered table-hover">
                <thead>
                    <tr>
                        <th>Title</th>
                        <th>User Create</th>
                        <th style="width: 100px;">Date Update</th>
                        <th style="width: 80px;">Action</th>
                    </tr>
                </thead>
                <tbody>
                    @foreach (var item in Model.ListPost)
                    {
                        <tr>
                            <td><a href="@Url.Action("Detail", "PostFrontEnd", new { area = "", url = item.Url, id = item.Id})" title="Xem chi tiết" target="_blank">@item.Title</a></td>
                            <td>@item.CreateUserName</td>
                            <td>@string.Format("{0: dd/MM/yyyy}",item.DateUpdate)</td>
                            <td>
                                @{
                                    var membership = (WebMatrix.WebData.SimpleMembershipProvider)Membership.Provider;
                                    int idUser = membership.GetUserId(User.Identity.Name);
                                }
                                @if (item.CreateUserId == idUser || User.IsInRole(YanForum.Engine.ViewModels.UserRoles.Admin))
                                {
                                    <a href="javascript:;" data-postid="@item.Id" id="btnPostDelete" class="i-action btnPostDelete" title="Xóa bài viết này"><i class="glyphicon glyphicon-remove"></i></a>
                                    <a href="@Url.Action("Update", "Post", new { area = "Admin", id = item.Id})" class="i-action" title="Cập nhật thông tin bài viết"><i class="glyphicon glyphicon-pencil"></i></a>
                                }else{
                                    <a href="javascript:;" class="i-action">&nbsp;&nbsp;&nbsp;</a>
                                    <a href="javascript:;" class="i-action">&nbsp;&nbsp;&nbsp;</a>
                                }
                            </td>
                        </tr>
                    }
                </tbody>
            </table>
            if (Model.TotalCount > Model.ListPost.Count)
            {
                string url = Url.Action("Index", "Post", new { area = "Admin" });
                <div class="col-md-12 text-center">
                    <nav>
                        @{Html.RenderAction("Pagging", "Partial", new { area = "", linktext = url + "?search=" + Model.Options.Search, totalCount = Model.TotalCount, pageSize = Model.Options.PageSize, pageIndex = Model.Options.PageIndex });}
                    </nav>
                </div>
            }
            
        }else{
            <div class="alert alert-info">
                Chưa có bài viết nào
            </div>
        }
    </div>
</div>
